<!--
 * @Author: daidai
 * @Date: 2022-02-20 16:16:42
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2022-10-25 09:18:22
 * @FilePath: \web-pc\src\pages\big-screen\view\indexs\left-center.vue
-->
<template>
  <Echart id="leftCenter" v-if="pageflag" :options="options" isClick class="left_center_inner" ref="charts"
    height="230px" @chartClick="chartClick" />
  <Reacquire v-else @onclick="getData" style="line-height: 200px">
    重新获取
  </Reacquire>
</template>

<script>
import { currentPOST } from 'api/modules';
import { colorsC, colorsB, legend, xAxis, yAxis } from '@/config/EChartVar';
import { graphic } from 'echarts';

export default {
  data() {
    return {
      options: {},
      tag: 1,
      countUserNumData: {
        axisData: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月'].reverse(),
        seriesData: [87, 85, 82, 79, 83, 89, 81, 86],
      },
      pageflag: true,
      timer: null,
    };
  },
  created() {
    this.getData();
  },
  mounted() { },
  beforeDestroy() {
    this.clearData();
  },
  methods: {
    clearData() {
      if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
      }
    },
    getData() {
      this.pageflag = true;

      this.$nextTick(() => {
        this.init(this.countUserNumData);
      });
    },
    //轮询
    switper() {
      if (this.timer) {
        return;
      }
      let looper = (a) => {
        this.getData();
      };
      this.timer = setInterval(
        looper,
        2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
      );
      let myChart = this.$refs.charts.chart;
      myChart.on('mouseover', (params) => {
        this.clearData();
      });
      myChart.on('mouseout', (params) => {
        this.timer = setInterval(
          looper,
          2000 // this.$store.state.setting.echartsAutoTime // staticAutoTime
        );
      });
    },
    init(currentData) {
      // let axisData = ["2021年", "2022年", "2023年", "2024年"];
      let axisData = currentData.axisData;
      let seriesData = [[...currentData.seriesData]];

      const options = {
        // backgroundColor: "#0F224C", //背景色
        grid: {
          top: '10%',
          left: '4%',
          right: '8%',
          bottom: '6%',
          containLabel: true,
        },
        legend: {
          show: false,
          top: '1%',
          left: '4%',
          icon: 'circle',
          itemWidth: 12,
          itemHeight: 12,
          // itemGap: 60,
          textStyle: legend.textStyle,
          data: ['运输成本'],
        },
        xAxis: {
          type: 'category',
          data: axisData,
          // boundaryGap: false,
          boundaryGap: true,
          splitLine: {
            show: false,
          },
          axisTick: {
            show: false, // 不显示下切线
          },
          axisLabel: xAxis.axisLabel,
          axisLine: {
            lineStyle: {
              background: 'rgba(176, 215, 255, 0.4)',
            },
          },
        },
        yAxis: [
          {
            type: 'value',
            max: 100,
            // min: 20, //
            // interval: 20,
            axisLabel: yAxis.axisLabel,
            axisLine: {
              show: false,
              // interval: 11,
              lineStyle: {
                color: 'rgba(0,0,0,0.5)',
              },
            },
            splitLine: {
              show: true,
              // interval: 1,
              lineStyle: {
                color: ['rgba(176, 215, 255, 0.2)'],
                width: 1,
                type: 'dashed',
              },
            },
            // splitLine: {
            //   show: false,
            // },
            axisTick: {
              show: false,
            },
          },
        ],
        series: [],
      };
      const series = [
        {
          name: '运输成本',
          type: 'bar',
          // 动画配置
          animation: true,
          animationDuration: 2000,
          animationEasing: 'quarticInOut',
          animationDelay: function (idx) {
            return idx * 150;
          },
          smooth: true,
          showSymbol: false,
          // symbol: 'circle',
          // symbolSize: 6,
          // barGap: '-30%',
          barWidth: 35,
          data: seriesData[0],
          itemStyle: {
            normal: {
              color: colorsC[0],
            },
          },
          // areaStyle: {
          //   color: colorsB[1],
          // },
          lineStyle: {
            normal: {
              width: 1,
            },
          },
          label: {
            show: false,
            position: 'top',
            formatter: (par) => {
              return par.value + '';
            },
            textStyle: { fontSize: 12, color: '#FFF' },
          },
          markPoint: {
            symbol: 'circle',
            symbolSize: [14, 14], // 容器大小
            symbolOffset: ['0%', '0%'],
            data: [
              {
                name: '最大值',
                type: 'max',
                valueIndex: 1,
              },
            ],
            label: {
              show: true,
              position: 'top',
              fontSize: 12,
              color: "rgba(0,219,254, 1)",
              formatter: (par) => {
                return par.value + '';
              },
            },
          },
        },
      ];
      options.series = series;
      this.options = options;
    },
    chartClick(params) {
      console.log('点击的数据:', params);
      // 这里处理你的点击逻辑
      this.$emit('chartClick', params, '物流园区活跃度', 'LeftCenterBottom');
    },
  },
};
</script>
<style lang="scss" scoped></style>
